package com.mingqijia.gassafety.job.hangzhou.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mingqijia.gassafety.authority.api.resp.config.DictionaryItemRespDTO;
import com.mingqijia.gassafety.authority.dal.helper.ConfigureHolder;
import com.mingqijia.gassafety.db.hangzhou.entity.CityProduct;
import com.mingqijia.gassafety.db.hangzhou.mapper.CityProductMapper;
import com.mingqijia.gassafety.job.feign.ConsoleSkFeignClient;
import com.mingqijia.gassafety.job.hangzhou.request.CreateCityProductRequest;
import com.mingqijia.gassafety.job.hangzhou.service.CityDeviceService;
import com.mingqijia.gassafety.job.hangzhou.service.CityProductService;
import com.mingqijia.gassafety.job.hangzhou.service.HangZhouService;
import com.mingqijia.gassafety.job.request.ConsoleSkSupplierListRequest;
import com.mingqijia.gassafety.job.response.AlarmSupplierListVo;
import com.mingqijia.gassafety.job.response.ConsoleSkSupplierListResponse;
import com.mingqijia.gassafety.job.service.cmp.EquipmentCmpService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 杭州对接-产品信息 服务实现类
 * </p>
 *
 * @author wanghai
 * @since 2022-04-11
 */
@Slf4j
@Service
public class CityProductServiceImpl extends ServiceImpl<CityProductMapper, CityProduct> implements CityProductService {


    @Value("${gassafety.hangzhou.yhSpId}")
    private String hangzhouSpId;

    @Autowired
    CityDeviceService cityDeviceService;

    @Autowired
    CityProductService cityProductService;

    @Autowired
    ConfigureHolder holder;

    @Autowired
    private EquipmentCmpService equipmentCmpService;

    @Autowired
    HangZhouService hangZhouService;


    private static int responseCode = 200;

    @Override
    public void createCityProduct() {
        //所有产品类型
        List<DictionaryItemRespDTO> equipmentType = holder.getDictionaryByKey("Equipment_type",hangzhouSpId);
        //所有厂商
//        List<DictionaryItemRespDTO> equipmentManufacturer = holder.getDictionaryByKey("Equipment_manufacturer", hangzhouSpId);
        // 查询远程接口，不查字典
        ConsoleSkSupplierListResponse resp = equipmentCmpService.supplierListRequest();
        List<DictionaryItemRespDTO> equipmentManufacturer = new ArrayList<>();
        if (null != resp && null != resp.getData() && CollectionUtils.isNotEmpty(resp.getData()) ) {
            log.info("结束调用厨房查询厂商接口，返回数据长度：{}", resp.getData().size());
            equipmentManufacturer = resp.getData().stream().map(item -> {
                DictionaryItemRespDTO re = new DictionaryItemRespDTO();
                re.setId(item.getAlarmSystemCode());
                re.setName(item.getMsName());
                re.setDictCode("Equipment_manufacturer");
                re.setValue(item.getAlarmSystemCode());
                re.setDescription(item.getMsName());
                return re;
            }).collect(Collectors.toList());
        }



        CreateCityProductRequest request = new CreateCityProductRequest();
        request.setEquipmentManufacturer(equipmentManufacturer);
        request.setEquipmentType(equipmentType);

        //调用接口,将字典传递
        String response = hangZhouService.createCityProduct(request);

        log.info("createCityProduct---end response:{}",response);


    }

}
